//
//  EveryStoryTableViewCell.m
//  littleLight's Project-A
//
//  Created by dllo on 16/5/15.
//  Copyright © 2016年 light. All rights reserved.
//

#import "EveryStoryTableViewCell.h"

#import "EveryStoryCollectionViewCell.h"
#import "EveryDayDetailViewController.h"
@implementation EveryStoryTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
        
    }
    return self;

}

- (void)createCollectionView
{
     
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - 30) / 2, 200);
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 430) collectionViewLayout:flowLayout];
    self.collectionV.backgroundColor = [UIColor colorWithRed:251 / 255.0 green:248 / 255.0  blue:241 / 255.0 alpha:1];
    [self.contentView addSubview:self.collectionV];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    
    [self.collectionV registerClass:[EveryStoryCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    


}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return self.array.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    EveryStoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    EveryDayModel *model = [self.array objectAtIndex:indexPath.row];
    
    cell.model = model;
    
   // [self.collectionV reloadData];
    
    
    return cell;
    
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    EveryDayModel *model = [self.array objectAtIndex:indexPath.row];
    self.Block(model);
    
 
}

@end
